package com.dlc.shop.bean;

import cn.hutool.core.collection.CollectionUtil;
import com.dlc.shop.bean.bo.SmsInfoBo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Yami
 */
public class SmsInfoContext {

    /** The request holder. */
    private static final ThreadLocal<List<SmsInfoBo>> SMS_INFO_HOLDER = new ThreadLocal<List<SmsInfoBo>>();


    public static List<SmsInfoBo> get(){

        List<SmsInfoBo> list = SMS_INFO_HOLDER.get();
        if (CollectionUtil.isEmpty(list)) {
            return new ArrayList<>();
        }
        return SMS_INFO_HOLDER.get();
    }

    public static void set(List<SmsInfoBo> smsInfoBos){
         SMS_INFO_HOLDER.set(smsInfoBos);
    }

    public static void put(SmsInfoBo smsInfoBo){
        List<SmsInfoBo> smsInfoBos = SMS_INFO_HOLDER.get();
        if (CollectionUtil.isEmpty(smsInfoBos)) {
            smsInfoBos = new ArrayList<>();
        }
        smsInfoBos.add(smsInfoBo);
        SMS_INFO_HOLDER.set(smsInfoBos);
    }

    public static void clean() {
        if (SMS_INFO_HOLDER.get() != null) {
            SMS_INFO_HOLDER.remove();
        }
    }
}
